Skip to content

Add translator for hstore type - #3070

Closed
weilence wants to merge 1 commit into
npgsql:mainfrom
weilence:main
Closed

weilence wants to merge 1 commit into
npgsql:mainfrom
weilence:main

Conversation

@weilence

Copy link
Copy Markdown

for example:
a["b"] will translate to "a" -> 'b'

If there is no translator, using the values of fields with the hstore type as a WHERE condition would be very cumbersome, and can only be achieved using FromSqlRaw.`

@roji
roji force-pushed the main branch 9 times, most recently from 79fae3a to f894de9 Compare February 16, 2026 16:00
@roji
roji force-pushed the main branch 2 times, most recently from 75c2ea9 to d038259 Compare February 25, 2026 14:25
@oONoobMasterOo

Copy link
Copy Markdown

please when this gets done? or any workaround?

Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The translator excludes immutable dictionary indexers despite the provider supporting their hstore mapping.

1 open issue
What changed in this PR

Adds hstore dictionary-indexer translation to the PostgreSQL query pipeline, allowing key lookups in LINQ predicates and projections without raw SQL.

Changes:

  • Translates dictionary indexing into PostgreSQL’s -> operator.
  • Integrates string type mapping, SQL generation, and nullable lookup results.
  • Adds functional tests for key expressions, projections, string operations, and null semantics.
File Description
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​HstoreTranslationsTest.cs Tests lookup results and generated SQL.
src/​EFCore.PG/​Query/​NpgsqlSqlExpressionFactory.cs Assigns lookup operand and result mappings.
src/​EFCore.PG/​Query/​Internal/​NpgsqlSqlNullabilityProcessor.cs Treats hstore lookup results as nullable.
src/​EFCore.PG/​Query/​Internal/​NpgsqlQuerySqlGenerator.cs Emits the -> operator.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlMethodCallTranslatorProvider.cs Registers the hstore translator.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlHstoreTranslator.cs Translates mapped dictionary indexers.
src/​EFCore.PG/​Query/​Expressions/​PgExpressionType.cs Defines the hstore lookup expression kind.
src/​EFCore.PG/​Query/​Expressions/​Internal/​PgBinaryExpression.cs Adds diagnostic printing for hstore lookups.

Review effort: Balanced

IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
=> method is { Name: "get_Item", DeclaringType: var declaringType }
&& declaringType == typeof(Dictionary<string, string>)
Copilot AI balanced review requested due to automatic review settings October 23, 2026 19:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reusing JSON traversal produces invalid SQL when hstore lookups are composed with string members such as Length.

2 open issues

Review effort: Balanced

return null;
}

return _sqlExpressionFactory.JsonTraversal(instance, arguments, false, typeof(string), _stringTypeMapping);
@roji

roji commented Oct 24, 2026

Copy link
Copy Markdown
Member

Sorry for not reviewing this earlier. As this PR has some issues (the usage of the JSON traversal operator is problematic) and is already fully covered by #3285, I'll focus on the latter and go ahead and close this one. Thanks for your work here and sorry again that it wasn't reviewed in a timely manner.

@roji roji closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants